Return reverse string


Posted by Christy on 2022-04-21

Description: Write a function named reverse that accepts a string and return the reversed string

Note: Don’t use the built-in function reverse()

function reverse(str) {
  let result = "";
  for (let i = str.length - 1; i >= 0; i--) {
    result += str[i];
  }
  return result;
}

console.log(reverse("abcd")); // dcba
console.log(reverse("12345aa")); // aa54321









Related Posts

fs_cli後台指令集

fs_cli後台指令集

第二周筆記 (JS) -4

第二周筆記 (JS) -4

[Kotlin]擺脫靜態公用程式類別:頂層函式和屬性

[Kotlin]擺脫靜態公用程式類別:頂層函式和屬性


Comments